package abq2.jic.jic.plugin.other.other.mob.mob;

import kd.bos.form.MobileFormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.control.*;
import kd.bos.form.plugin.AbstractMobFormPlugin;
import kd.bos.list.MobileListShowParameter;

import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;

public class BookMobHomePlugin extends AbstractMobFormPlugin {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        /*IFrame iframe = this.getView().getControl("kdec_iframeap");
        String mainurl = System.getProperty("domain.contextUrl");
        mainurl = mainurl + "/mobile.html?form=kdec_main_bhm";
        iframe.setSrc(mainurl);*/


        MobileFormShowParameter showParameter = new MobileFormShowParameter();
        showParameter.setFormId("kdec_main_bhm");
        showParameter.getOpenStyle().setTargetKey("kdec_flex_container");
        showParameter.getOpenStyle().setShowType(ShowType.InContainer);
        getView().showForm(showParameter);
    }

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        addClickListeners("kdec_home", "kdec_my");
    }

    @Override
    public void click(EventObject evt) {
        super.click(evt);
        if (evt.getSource() instanceof Control) {
            switch ( ((Control)evt.getSource()).getKey() ) {
                case "kdec_home": {

                    /*IFrame iframe = this.getView().getControl("kdec_iframeap");
                    String mainurl = System.getProperty("domain.contextUrl");
                    mainurl = mainurl + "/mobile.html?form=kdec_main_bhm";
                    iframe.setSrc(mainurl);*/

                    MobileFormShowParameter showParameter = new MobileFormShowParameter();
                    showParameter.setFormId("kdec_main_bhm");
                    showParameter.getOpenStyle().setTargetKey("kdec_flex_container");
                    showParameter.getOpenStyle().setShowType(ShowType.InContainer);
                    getView().showForm(showParameter);

                    Map fieldMap = new HashMap();
                    fieldMap.put("imageKey", "/icons/mobile/tab_bar/icon_homepage_64_64.png");
                    getView().updateControlMetadata("kdec_home", fieldMap);
                    Map fieldMap2 = new HashMap();
                    fieldMap2.put("imageKey", "/icons/mobile/tab_bar/icon_my(x)_64_64.png");
                    getView().updateControlMetadata("kdec_my", fieldMap2);
                }
                    break;
                case "kdec_my": {

                    MobileFormShowParameter showParameter = new MobileFormShowParameter();
                    showParameter.setFormId("kdec_my_bhm");
                    showParameter.getOpenStyle().setTargetKey("kdec_flex_container");
                    showParameter.getOpenStyle().setShowType(ShowType.InContainer);
                    getView().showForm(showParameter);

                    /*IFrame iframe = this.getView().getControl("kdec_iframeap");
                    String mainurl = System.getProperty("domain.contextUrl");
                    mainurl = mainurl + "/mobile.html?form=kdec_my_bhm";
                    iframe.setSrc(mainurl);*/

                    Map fieldMap = new HashMap();
                    fieldMap.put("imageKey", "/icons/mobile/tab_bar/icon_homepage(x)_64_64.png");
                    getView().updateControlMetadata("kdec_home", fieldMap);
                    Map fieldMap2 = new HashMap();
                    fieldMap2.put("imageKey", "/icons/mobile/tab_bar/icon_my_64_64.png");
                    getView().updateControlMetadata("kdec_my", fieldMap2);
                }
                    break;
            }
        }
    }



}
